package org.htmlparser;

import java.io.Serializable;

public class Attribute
  implements Serializable
{
  protected String mAssignment;
  protected String mName;
  protected char mQuote;
  protected String mValue;

  public Attribute()
  {
    this(null, null, null, ');
  }

  public Attribute(String paramString)
    throws IllegalArgumentException
  {
    if (paramString.trim().length() != 0)
      throw new IllegalArgumentException("non whitespace value");
    setName(null);
    setAssignment(null);
    setValue(paramString);
    setQuote(');
  }

  public Attribute(String paramString1, String paramString2, String paramString3)
  {
    this(paramString1, paramString2, paramString3, ');
  }

  public Attribute(String paramString1, String paramString2, String paramString3, char paramChar)
  {
    setName(paramString1);
    setAssignment(paramString2);
    if (paramChar == 0)
      setRawValue(paramString3);
    while (true)
    {
      return;
      setValue(paramString3);
      setQuote(paramChar);
    }
  }

  public String getAssignment()
  {
    return this.mAssignment;
  }

  public void getAssignment(StringBuffer paramStringBuffer)
  {
    if (this.mAssignment != null)
      paramStringBuffer.append(this.mAssignment);
  }

  public int getLength()
  {
    int i = 0;
    String str1 = getName();
    if (str1 != null)
      i = 0 + str1.length();
    String str2 = getAssignment();
    if (str2 != null)
      i += str2.length();
    String str3 = getValue();
    if (str3 != null)
      i += str3.length();
    if (getQuote() != 0)
      i += 2;
    return i;
  }

  public String getName()
  {
    return this.mName;
  }

  public void getName(StringBuffer paramStringBuffer)
  {
    if (this.mName != null)
      paramStringBuffer.append(this.mName);
  }

  public char getQuote()
  {
    return this.mQuote;
  }

  public void getQuote(StringBuffer paramStringBuffer)
  {
    if (this.mQuote != 0)
      paramStringBuffer.append(this.mQuote);
  }

  public String getRawValue()
  {
    String str;
    if (isValued())
    {
      char c = getQuote();
      if (c != 0)
      {
        StringBuffer localStringBuffer = new StringBuffer();
        localStringBuffer.append(c);
        getValue(localStringBuffer);
        localStringBuffer.append(c);
        str = localStringBuffer.toString();
      }
    }
    while (true)
    {
      while (true)
      {
        return str;
        str = getValue();
      }
      str = null;
    }
  }

  public void getRawValue(StringBuffer paramStringBuffer)
  {
    getQuote(paramStringBuffer);
    getValue(paramStringBuffer);
    getQuote(paramStringBuffer);
  }

  public String getValue()
  {
    return this.mValue;
  }

  public void getValue(StringBuffer paramStringBuffer)
  {
    if (this.mValue != null)
      paramStringBuffer.append(this.mValue);
  }

  public boolean isEmpty()
  {
    int i;
    if ((getAssignment() != null) && (getValue() == null))
      i = 1;
    while (true)
    {
      return i;
      i = 0;
    }
  }

  public boolean isStandAlone()
  {
    int i;
    if ((getName() != null) && (getAssignment() == null))
      i = 1;
    while (true)
    {
      return i;
      i = 0;
    }
  }

  public boolean isValued()
  {
    int i;
    if (getValue() != null)
      i = 1;
    while (true)
    {
      return i;
      i = 0;
    }
  }

  public boolean isWhitespace()
  {
    int i;
    if (getName() == null)
      i = 1;
    while (true)
    {
      return i;
      i = 0;
    }
  }

  public void setAssignment(String paramString)
  {
    this.mAssignment = paramString;
  }

  public void setName(String paramString)
  {
    this.mName = paramString;
  }

  public void setQuote(char paramChar)
  {
    this.mQuote = paramChar;
  }

  public void setRawValue(String paramString)
  {
    char c1 = ';
    if ((paramString != null) && (paramString.trim().length() != 0))
    {
      if ((!(paramString.startsWith("'"))) || (!(paramString.endsWith("'"))) || (2 > paramString.length()))
        break label68;
      c1 = '\'';
      paramString = paramString.substring(1, paramString.length() - 1);
    }
    while (true)
    {
      while (true)
      {
        label68: int j;
        while (true)
        {
          int i;
          int k;
          do
          {
            while (true)
            {
              setValue(paramString);
              setQuote(c1);
              return;
              if ((!(paramString.startsWith("\""))) || (!(paramString.endsWith("\""))) || (2 > paramString.length()))
                break;
              c1 = '"';
              paramString = paramString.substring(1, paramString.length() - 1);
            }
            i = 0;
            j = 1;
            k = 1;
            int l = 0;
            if (l < paramString.length())
            {
              char c3 = paramString.charAt(l);
              if ('\'' == c3)
              {
                j = 0;
                i = 1;
              }
              while (true)
              {
                do
                  while (true)
                  {
                    while (true)
                      ++l;
                    if ('"' != c3)
                      break;
                    k = 0;
                    i = 1;
                  }
                while (('-' == c3) || ('.' == c3) || ('_' == c3) || (':' == c3) || (Character.isLetterOrDigit(c3)));
                i = 1;
              }
            }
          }
          while (i == 0);
          if (k == 0)
            break;
          c1 = '"';
        }
        if (j == 0)
          break;
        c1 = '\'';
      }
      c1 = '"';
      StringBuffer localStringBuffer = new StringBuffer(paramString.length() * ("&quot;".length() - 1));
      int i1 = 0;
      if (i1 < paramString.length())
      {
        char c2 = paramString.charAt(i1);
        if (c1 == c2)
          localStringBuffer.append("&quot;");
        while (true)
        {
          while (true)
            ++i1;
          localStringBuffer.append(c2);
        }
      }
      paramString = localStringBuffer.toString();
    }
  }

  public void setValue(String paramString)
  {
    this.mValue = paramString;
  }

  public String toString()
  {
    StringBuffer localStringBuffer = new StringBuffer(getLength());
    toString(localStringBuffer);
    return localStringBuffer.toString();
  }

  public void toString(StringBuffer paramStringBuffer)
  {
    getName(paramStringBuffer);
    getAssignment(paramStringBuffer);
    getRawValue(paramStringBuffer);
  }
}